package com.tronsis.library.util;

import android.app.Activity;
import android.view.WindowManager;

/**
 * Created by 16172 on 2018/10/26.
 */

public class WindowUtil {

    /**
     * 设置透明度(context)
     * @param bgAlpha[0-1] 1表示不透明
     */
    public static void setPopWindowBackgroundAlpha(Activity activity, float bgAlpha)
    {
        WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
        lp.alpha = bgAlpha; //[0.0-1.0]
        if (bgAlpha == 1) {
            //不移除该Flag的话,在有视频的页面上的视频会出现黑屏的bug,而我遇到的是半透明无效，采用了该方案
            activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        } else {
            //此行代码主要是解决在华为手机上半透明效果无效的bug
            activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        }
        activity.getWindow().setAttributes(lp);
    }
}
